package com.ruoyi.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.order.domain.SyCourseOrders;
import com.ruoyi.order.service.ISyCourseOrdersService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程订单Controller
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/order/courseOrders")
public class SyCourseOrdersController extends BaseController
{
    @Autowired
    private ISyCourseOrdersService syCourseOrdersService;

    /**
     * 查询课程订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:courseOrders:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyCourseOrders syCourseOrders)
    {
        startPage();
        List<SyCourseOrders> list = syCourseOrdersService.selectSyCourseOrdersList(syCourseOrders);
        return getDataTable(list);
    }

    /**
     * 导出课程订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:courseOrders:export')")
    @Log(title = "课程订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyCourseOrders syCourseOrders)
    {
        List<SyCourseOrders> list = syCourseOrdersService.selectSyCourseOrdersList(syCourseOrders);
        ExcelUtil<SyCourseOrders> util = new ExcelUtil<SyCourseOrders>(SyCourseOrders.class);
        util.exportExcel(response, list, "课程订单数据");
    }

    /**
     * 获取课程订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:courseOrders:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return success(syCourseOrdersService.selectSyCourseOrdersByOrderId(orderId));
    }
    @PreAuthorize("@ss.hasPermi('order:courseOrders:query')")
    @GetMapping(value = "/getUserCourse/{orderId}")
    public AjaxResult getInfos(@PathVariable("orderId") String orderId)
    {
        return success(syCourseOrdersService.selectSyCourseOrdersUsersByOrderId(orderId));
    }

    //courseOrderALL 查询所有课程订单数量
    @PreAuthorize("@ss.hasPermi('order:courseOrders:query')")
    @GetMapping(value = "/courseOrderALL")
    public AjaxResult courseOrderALL()
    {
        return success(syCourseOrdersService.courseOrdersAll());
    }

    /**
     * 新增课程订单
     */
    @PreAuthorize("@ss.hasPermi('order:courseOrders:add')")
    @Log(title = "课程订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyCourseOrders syCourseOrders)
    {
        return toAjax(syCourseOrdersService.insertSyCourseOrders(syCourseOrders));
    }

    /**
     * 修改课程订单
     */
    @PreAuthorize("@ss.hasPermi('order:courseOrders:edit')")
    @Log(title = "课程订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyCourseOrders syCourseOrders)
    {
        return toAjax(syCourseOrdersService.updateSyCourseOrders(syCourseOrders));
    }

    /**
     * 删除课程订单
     */
    @PreAuthorize("@ss.hasPermi('order:courseOrders:remove')")
    @Log(title = "课程订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(syCourseOrdersService.deleteSyCourseOrdersByOrderIds(orderIds));
    }
}
